

							


//var baseURL = 'https://www.kadbuster.com';

// 测试
var baseURL = 'https://tennis.wexiang.vip';

var videoURL = 'https://u502114-9755-0e654a68.yza1.seetacloud.com:8443/'

// uni.setStorageSync('upimg', baseURL);//上传地址

export function request(app) {
	app.config.globalProperties.apiurl = baseURL //上传地址
	app.config.globalProperties.videoURL = videoURL //上传地址
	app.config.globalProperties.http = (urls, data, method,isload) => {
		if(!isload){
			uni.showLoading()
		}
	
		// if (process.env.NODE_ENV === 'development') {
		// 	var url = 'bsapi' + urls
		// } else {
		// 	var url = baseURL + urls
		// }
		var url = baseURL + urls
		
		
		
		let token = ''
		if(uni.getStorageSync("token")){
			token = 'Bearer '+ uni.getStorageSync("token")
		}
 
				
		 
		return new Promise(function(resolve, reject) {
			uni.request({
				url,
				header: {
					'Authori-Zation':token
				},
				method: method ? method : 'GET',
				data: data ? data : {},
				success: (res) => {
					if(res.statusCode == 200){
						if (res.data.status == 200) {
							resolve(res.data);
						}else if(res.data.status == 110005||res.data.status == 110002){
							uni.removeStorageSync('token')
							
							uni.showToast({
								title: '请登录',
								icon: "none"
							})
							uni.reLaunch({
								url:"/pages/login/index"
							})
							
						} else{
							uni.showToast({
								title: res.data.msg || res.data.message,
								icon: "none"
							})
							reject(res);
						}
					}else if (res.statusCode == 401) {
						uni.removeStorageSync('token')
						uni.showToast({
							title: 'Login has expired',
							icon: "none"
						})
						uni.reLaunch({
							url:"/pages/login/index"
						})
						
						reject(res.data)
					} else {
						reject(res)
						uni.showToast({
							title: res.data.msg || res.data.message,
							icon: "none"
						})
						if (res.message) {
							uni.showToast({
								title: res.message,
								icon: "none"
							})
						} else {
							uni.showToast({
								title: res.data.message,
								icon: "none"
							})
						}
					}
				},
				complete() {
					
					if(!isload){
						uni.hideLoading()
					}
					
				},
				fail: (res) => {
					reject(res)
					// uni.showToast({
					// 	title: "Frequent system",
					// 	icon: "none"
					// })
				}
			})
		})
	}
}